package com.amado.easyui2.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.amado.easyui2.dao.StudentDao;
import com.amado.easyui2.domain.StudentEntity;
import com.amado.easyui2.exception.ApiException;
import com.amado.easyui2.enums.ApiErrorEnum;
import com.amado.easyui2.service.StudentService;

@Service
public class StudentServcieImpl implements StudentService {
	//一定要通过Spring管理StudentDao对象，内部的依赖对象才会注入
	@Autowired
	private StudentDao studentDao;

	@Override
	public void addStudent(StudentEntity idNumber) {
		if(idNumber==null) {
			throw new ApiException(ApiErrorEnum.ERROR_100);
		}
		StudentEntity returnStu=studentDao.getByName(idNumber.getIdNumber());
		if(returnStu!=null) {
			throw new ApiException(ApiErrorEnum.ERROR_1001);
		}
		studentDao.addStudent(idNumber);

	}

	@Override
	public int deleteStudent(Long[] id) {
		return studentDao.deleteStudent(id);
	}

	@Override
	public int updateStudent(StudentEntity idNumber) {
		return studentDao.updateStudent(idNumber);

	}

	@Override
	public List<StudentEntity> listAll(String name,String idNumber) {
		// TODO Auto-generated method stub
		return studentDao.listAll(name,idNumber);
	}

	@Override
	public StudentEntity getById(Long id) {
		// TODO Auto-generated method stub
		return studentDao.getById(id);
	}

}
